package com.label.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.label.common.CommonResult;
import com.label.entity.Log;
import com.label.entity.User;
import com.label.service.LogService;
import com.label.service.UserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Jianhua
 * @since 2022-03-27
 */
@Api
@RestController
@RequestMapping("/api/log")
public class LogController {
    @Autowired
    LogService logService;
    @RequestMapping("/list")
    CommonResult list(ModelMap modelMap, Page page1, @ModelAttribute("log")Log log,Integer page,Integer pageSize){
        page1.setCurrent(page);
        page1.setSize(pageSize);
        page1 =logService.pageList(page1,log);
        modelMap.addAttribute("page",page1);
        return CommonResult.success(page1);
    }
    @RequestMapping("/save")
    CommonResult save(Log log){
        return CommonResult.success(logService.saveOrUpdate(log));
    }
    //id查询
    @RequestMapping("/getByid")
    CommonResult getByid(Integer id){
        return CommonResult.success(logService.getById(id));
    }
    //逻辑删除
    @RequestMapping("/del")
    CommonResult del(Integer id){
        Log log=logService.getById(id);
//    user.setUserState("o");
        return CommonResult.success(logService.updateById(log));
    }
    //批量删除
    @RequestMapping("/delByIds")
    CommonResult delByIds(Integer[] id){

        return CommonResult.success(logService.removeByIds(Arrays.asList(id)));
    }
//    模糊查询
    @RequestMapping("/getBylike")
    CommonResult getBylike(ModelMap modelMap, Page page1, Integer page,Integer pageSize,String key){
        page1.setCurrent(page);
        page1.setSize(pageSize);
        page1 =logService.getBylike(page1,key);
        modelMap.addAttribute("page",page1);
        return CommonResult.success(page1);
    }
}

